<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
    <title>新闻详情-牛马新闻中心</title>
    <script type="text/javascript" src="../JS/CheckLogin.js" defer="defer"></script>
    <link rel="stylesheet" type="text/css" href="../CSS/News_detail.css"/>
    <!--检查登录态-->

</head>
<body class="News_D">
    <%@ include file="Header.jsp" %>
    <div class="new_detail" id="new_detail">
        <span id="title">${title}</span><br/>
        <span id="author">${author}</span><br/>
        <span id="type">${type}</span><br/>
        <span id="time">${time}</span><br/>
        <span id="content">${content}</span><br/>
    </div>
    <div class="new_recommend" id="new_recommend">
        <span style="font-size: 24px;">相关新闻</span><br/>
        <span class="news_title">${title}</span><br/><br/>
        <span class="news_title">${title}</span><br/><br/>
        <span class="news_title">${title}</span><br/><br/>
        <span class="news_title">${title}</span><br/><br/>
        <span class="news_title">${title}</span><br/><br/>
        <%-- <c:forEach items="${Newtest}" var="i" begin="1" end="5" step="1" varStatus="s">
        	<span class="news_title">${i.title}</span><br/><br/>
        </c:forEach> --%>
    </div>
</body>
<script type="text/javascript">
    function GYS(k){
    	var NTitle = document.getElementsByClassName('news_title');
        for(var i=0;i<k;i++){
            NTitle[i].onmousedown=function () {
                this.style.color='red';
            }
            NTitle[i].onmouseup=function () {
                this.style.color='blue';
            }
        }
    }
</script>
<!--更改字体颜色-->
<script type="text/javascript">
    function GO(nT) {
        window.localStorage.setItem("title",nT.innerHTML);
        window.location="News_detail.jsp";
    }
</script>
<!--新闻标题点击事件-->
<script type="text/javascript">
    function ajaxFunction() {
        var xmlHttp;
        try { // Firefox, Opera 8.0+, Safari
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            try {// Internet Explorer
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                }
            }
        }
        return xmlHttp;
    }
    // 创建AJAX
    function Onloading() {
        var sql="Select *  from newsdetail INNER JOIN types on newsdetail.type = types.tid where title='"+localStorage.getItem("title")+"' ";
        var request = ajaxFunction();
        // 2 发送请求 参数1:选择发送方式  参数2:发送地址(这里发送给一个Servlet)  参数3:是否异步传输(一般为true)
        request.open("POST", "./../GetMessagesServlet", true);			//全部新闻
        // 3 获取请求响应数据 注册监听  状态如果发生变化 会执行等号右边的函数
        request.onreadystatechange = function() {
            //前半段表示 已经能够正常处理。  再判断状态码是否是200
            if (request.readyState == 4 && request.status == 200) {
                //弹出响应的信息
                var test = eval("("+request.responseText+")");
                console.log(test);
                localStorage.setItem("Mid",test[0].Mid);
                localStorage.setItem("type",test[0].type);
                var news ='<span id="title">'+test[0].title+'</span><br/><span id="author">'+test[0].author+'</span><br/><span id="type">'+test[0].tname+'</span><br/><span id="time">'+test[0].time+'</span><br/><span id="content">'+test[0].content+'</span><br/>';
                document.getElementById("new_detail").innerHTML=news;
            }
        }
        request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        request.send("sql="+sql);
    }
    Onloading();
    function Onloading2(){
    	var sql = "Select * from newsdetail INNER JOIN types on newsdetail.type = types.tid where type = '"+localStorage.getItem("type")+"' and title !='"+localStorage.getItem("title")+"'";
    	var request1 = ajaxFunction();
    	request1.open("POST","./../GetMessagesServlet",true);
    	request1.onreadystatechange = function(){
    		if(request1.readyState == 4 && request1.status == 200){
    			 var Newtest = eval("("+request1.responseText+")");
    			 var newss = '<span style="font-size: 24px;">相关新闻</span><br/>';
    			 for(var i=0;i<Newtest.length;i++){
    				 newss+='<span class="news_title" onclick="GO(this)" title="'+Newtest[i].title+'">'+Newtest[i].title+'</span><br/><br/>';
    			 }
    			 document.getElementById("new_recommend").innerHTML=newss;
    			 GYS(Newtest.length);
    		}
    	}
    	request1.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    	request1.send("sql="+sql);
    	
    }
    setTimeout(function () {
        Onloading2();
    },300);
</script>
<!--获取数据-->
</html>